import BaseController from "../../cfw/mvc/BaseController";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import { UIIndex } from "../../cfw/tools/Define";
import LobbyManager from "./LobbyManager";
import DressingRoomController from "../dressroom/DressingRoomController";
import DecorationController from "../decoration/DecorationController";
import HouseController from "../decoration/HouseController";
import CristmasTreeController from "../tree/CristmasTreeController";
import CookeryController from "../cookery/CookeryController";
import ToiletController from "../toilet/ToiletController";
import BathRoomController from "../bathroom/BathRoomController";
import DininghallController from "../dininghall/DininghallController";
import BadRoomController from "../badroom/BadRoomController";
import SmallGameController from "../samllgame/SmallGameController";
import LoadingManager from "../loading/LoadingManager";
import SDKManager from "../../sdk/SDKManager";
import LoadingController from "../loading/LoadingController";
import OVNativeAdC from "../nativeAd/OVNativeAdC";
import { SDKEventName, BattleID } from "../../sdk/SDKConfig";
import FloatC from "../float/FloatC";
import GiftC from "../gift/GiftC";


export default class LobbyController extends BaseController {

    private static ins: LobbyController;

    static instance() {
        if (!this.ins) {
            this.ins = new LobbyController()
        }
        return this.ins;
    }
    protected addFlag: boolean = false;

    intoLayer() {
        ModuleManager.setModuleID(ModuleID.LOBBY)
        this.pushView('prefabs/LobbyView', 'LobbyView', new LobbyManager(), ModuleManager.getLoader(), UIIndex.ROOT)
        if (!this.addFlag) {

            SDKManager.getChannel().battleEnd(BattleID.LOGIN_TO_LOBBY)
            SDKManager.getChannel().battleEnd(BattleID.HIT_EGG_TO_LOBBY)
            this.addFlag = true;
        } else {
            SDKManager.getChannel().setShowFlag(true)
        }

    }

    getAddFlag() {
        return this.addFlag;
    }

    intoSuitcases() {
        // DressingRoomController.instance().intoSuitcases()
    }


    intoDecorationRoom() {
        DecorationController.instance().intoLayer()
    }

    intoOutDoor() {
        let hasSubPackage = SDKManager.getChannel().hasSubPackage()
        if (hasSubPackage) {
            LoadingController.instance().intoLayer(ModuleID.OUT_DOOR, [ModuleID.OUT_DOOR])
        } else {
            HouseController.instance().intoLayer()
        }
        SDKManager.getChannel().sendEvent(SDKEventName.outdoor)

    }

    intoGift() {
        let hasSubPackage = SDKManager.getChannel().hasSubPackage()
        if (hasSubPackage) {
            LoadingController.instance().intoLayer(ModuleID.GIFT, [ModuleID.GIFT])
        } else {
            GiftC.instance().intoLayer()
        }
    }

    intoCristmasRoom() {
        CristmasTreeController.instance().intoLayer();
    }


    intoCookie() {
        let hasSubPackage = SDKManager.getChannel().hasSubPackage()
        if (hasSubPackage) {
            LoadingController.instance().intoLayer(ModuleID.COOKIE, [ModuleID.COOKIE])
        } else {
            CookeryController.instance().intoLayer()
        }
    }



    intoWhere(num: number) {
        switch (num) {
            case 0:
                ToiletController.instance().intoLayer()
                break;
            case 1:
                BathRoomController.instance().intoLayer()
                break;
            case 2:
                DininghallController.instance().intoLayer()
                break;
            case 3:
                BadRoomController.instance().intoLayer()
                break
            case 4:
                SmallGameController.instance().intoLayer()
                break;
        }
    }

    intoDressingRoom(index: number) {
        DressingRoomController.instance().intoDressingRoom(index)
    }


    showNativeAd() {
        // OVNativeAdC.instance().intoLayer()
        if (SDKManager.getChannel().getShowFlag()) {
            SDKManager.getChannel().openNativeView()
            SDKManager.getChannel().setShowFlag(false)
        }

    }




}
